package com.tjyx.maintain.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tjyx.common.TJYXException;
import com.tjyx.common.action.BaseAction;
import com.tjyx.maintain.dao.UserInfoDao;

/**
 * 用户登录转发控制Action<br />
 * 时间：2012-3-26
 * 
 * @author zhutianjie
 * @version v1.0
 *
 */
public class LoginAction extends BaseAction {

	private UserInfoDao userInfoDao = new UserInfoDao();

	/**
	 * 用户登录
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	public String login(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
//		request.setAttribute(ERROR_ATTR, "登陆失败");
//		return ERROR_PAGE;
		return "maintain/main.jsp";
	}

	/**
	 * 用户登录注册
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	public String regist(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		try {
			userInfoDao.regist(userName, password);
		} catch (TJYXException e) {
			e.printStackTrace();
			request.setAttribute(ERROR_ATTR, e.getMessage());
			return ERROR_PAGE;
		}
		return "maintain/main.jsp";
	}

}
